<?
	if( (isset($_POST['submit'])) && ($_POST['submit'] == 1) ){
		$action = $_GET['action'];
		if($action == 'xoa'){
			$listId = $_POST['chon'];
			if($listId != ""){
				$db->query("DELETE FROM ".$prefix."tinnhanrieng WHERE tnr_id in('".str_replace(",","','",$listId)."')");
				Redirect("Xóa thành công !","".$root."/tin-nhan/");
			}
		}else{
			$listId = $_POST['chon'];
			if($listId != ""){
				$db->query("UPDATE ".$prefix."tinnhanrieng SET tnr_danhdau = 1 WHERE tnr_id in('".str_replace(",","','",$listId)."')");
				Redirect("Đánh dấu thành công !","".$root."/tin-nhan/");
			}
		}
	}
?>
<script language="javascript">
	function funAction(type){
		var f = document.getElementById('frmTinNhan');
		if(type == 0){
			f.action = '<?=$root?>/?mod=tinnhan&m=tinnhan&m=tingui&action=danhdau';
		}else{
			f.action = '<?=$root?>/?mod=tinnhan&m=tinnhan&m=tingui&action=xoa';
		}
	}
	function funChon(id){
		window.location = '<?=$root?>/?mod=tinnhan&m=tingui&sid=' + id;
	}
</script>
<div class="inb_title_tr">
    <div class="inb_title_tl">

        <div class="inb_title_top"></div>
    </div>
</div>

<div class="inb_title_body">
    <b>Tin đã nhận</b>
</div>

<div class="inb1">
    Chọn đ&#225;nh dấu:
    <select name="loc" onchange="funChon(this.value);">
	<option value="0" <? if($sid == 0){?> selected="selected" <? } ?>>----- Tất cả -----</option>
	<option value="1" <? if($sid == 1){?> selected="selected" <? } ?>>Đ&#227; đọc</option>

	<option value="2" <? if($sid == 2){?> selected="selected" <? } ?>>Chưa đọc</option>
	<option value="3" <? if($sid == 3){?> selected="selected" <? } ?>>Đ&#225;nh dấu</option>
	<option value="4" <? if($sid == 4){?> selected="selected" <? } ?>>Kh&#244;ng đ&#225;nh dấu</option>

</select>
</div>
<form action="<?=$root?>/?mod=tinnhan&m=tinnhan&action=xoa" name="frmTinNhan" id="frmTinNhan" method="post" onSubmit="return checkInput(this,'Bạn hãy chọn ít nhất một giá trị','Bạn chắc chắn muốn xoá không');">
<input type="hidden" name="chon" id="chon"/>
<div class="inb5">
    <table cellpadding="0" cellspacing="0" width="100%">
        <tr style="background-color:#f2f2f2;">
            <td width="42" align="center" valign="middle" style="width:30px;padding-left:6px;">
                <input type="checkbox" name="chkall" id="chkall" value="0" <? echo "onClick=\"docheck(this.form,0);\""?>>

          </td>
         	<td width="200" align="left" valign="middle" style="width:150px;">
				<a href="javascript:void(0);">Gửi đến</a>			</td>
			
            <td width="514" valign="middle" style="width:450px;">
                <a href="javascript:void(0);">Tiêu đề</a>            </td>
			
            <td width="120" align="left" valign="middle" style="width:100px;">

                <a href="javascript:void(0);">Ngày gửi</a>            </td>
        </tr>
   <?
   		$sql = "SELECT * FROM ".$prefix."tinnhanrieng WHERE tnr_nguoigui = '".$uid."'";
		if(isset($_GET['sid'])){
			$sid = $_GET['sid'];
			if($sid == 1){
				$sql .= " AND tnr_tinhtrang = 1";
			}else if($sid == 2){
				$sql .= " AND tnr_tinhtrang = 0";
			}else if($sid == 3){
				$sql .= " AND tnr_danhdau = 1";
			}else if($sid == 4){
				$sql .= " AND tnr_danhdau = 0";
			}else{
				$sql = $sql;
			}
		}
		$pp=10; 
		$parr=array();
		$parr=paging($sql,$pp);
		$page=$parr[0];
		$limitvalue=$parr[1];
		$numofpages=$parr[2];
		$sql.=" LIMIT $limitvalue, $pp";
		/////////////////////////////////////
   		$rs = $db->query($sql);
		while($row = $db->fetch_array($rs)){
		$tnr_id = $row[tnr_id];
		$tnr_nguoinhan = $row[tnr_nguoinhan];
		$tnr_tieude = $myString->unQuote(stripslashes($row[tnr_tieude]));
		$tnr_thoigian = format_date($row[tnr_thoigian]);
		$tnr_tinhtrang = $row[tnr_tinhtrang];
   ?>     
        <tr style="border-bottom:solid 1px #dedede;<? if($tnr_tinhtrang ==0){?> font-weight:bold; <? }?>">
            <td style="border-bottom:solid 1px #dedede;padding-left:6px;height:25px;" align="center">
               <input type="checkbox" name="Xoa" id="Xoa" value="<?=$tnr_id?>" onClick="docheckone(this.form);">
            </td>
           
		    <td align="left" style="border-bottom:solid 1px #dedede;">
                <?=tenNguoiDung($tnr_nguoinhan)?>

            </td>
			
            <td style="border-bottom:solid 1px #dedede;">
                <a class="messTitle" href="<?=$root?>/xem-tin-nhan/<?=$tnr_id?>"><?=$tnr_tieude?></a>
            </td>
			
            <td style="border-bottom:solid 1px #dedede;">
                <?=$tnr_thoigian?>

            </td>
        </tr>
      <? } ?>          
    </table>
</div>

<div class="inb2">
	<input type="hidden" name="submit" id="submit" value="1" />
    <input type="submit" name="danhdau" value=" Đánh dấu" onclick="funAction(0);"/>&nbsp;<input type="submit" name="xoa" value=" Xóa tin nhắn" onclick="funAction(1);"/>
    
    
</div>
</form>
<div class="inb3">
    <span>Ghi chú:</span>

    <span style="margin-left:20px;"><img src="<?=$root?>/themes/images/home/flag.jpg"/> Đã đánh dấu</span>
    <span style="margin-left:20px;"><img src="<?=$root?>/themes/images/home/Reply.jpg"/> Đã trả lời</span>
    <span style="margin-left:20px;"><img src="<?=$root?>/themes/images/home/Forward.jpg"/> Đã chuyển về email</span> 
</div>   

<div class="inb3">
   <br /><br /><br />
    <p align="left" class="font">
	 <?php echo page_div( "".$root."/?mod=tinnhan&m=tingui&sid=".$sid."&p=%d_pg", "10", ceil ( $numofpages ), $page ); ?>
	 </p>
</div>

<div class="BR" style="margin-bottom:4px;">
    <div class="BL">
        <div class="BodyBottom"></div>
    </div>
</div>